package com.vic.queue_param.durable;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.MessageProperties;
import com.vic.utils.RabbitmqUtils;

import java.nio.charset.StandardCharsets;

/**
 * 队列持久化、消息持久化
 */
public class Producer {

    public static void main(String[] args) throws Exception {

        String queueName = "queue_durable";
        Channel channel = RabbitmqUtils.getChannel();
        // 声明队列
        // 队列持久化，为true时，重启rabbitmq后，此队列依然存在。
        boolean durable = true;
        channel.queueDeclare(queueName, durable, false, false , null);

        // 消息持久化
        channel.basicPublish("", queueName, MessageProperties.PERSISTENT_TEXT_PLAIN, "好消息".getBytes(StandardCharsets.UTF_8));
        System.out.println("发送消息完成");

    }

}
